package Code.ArrayListClass;

import java.util.ArrayList;

public class Demo1 {
    public static void main(String[] args) {
        //创建集合对象
        //泛型：用于约束集合中存储元素的数据类型
        ArrayList<String> list = new ArrayList<>();
        System.out.println(list);

        //添加
        boolean result = list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        System.out.println(result);
        System.out.println(list);

        //删除
        boolean re = list.remove("f"); //如果元素不存在返回false，
        list.remove("a");
        //根据索引删除，会返回删除的元素；
        String str= list.remove(0);
        System.out.println(re);
        System.out.println(str);
        System.out.println(list);

        //修改
        String s = list.set(1,"ddddd");  //返回原来的字符
        System.out.println(s);
        System.out.println(list);

        //查询
        String a = list.get(0);
        System.out.println(a);

        //集合的长度
        System.out.println(list.size());

        //遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
